<?php
//Connection statement
require_once('../Connections/cn.php');


 $task = '';
  if ( isset($_POST['task'])){
    $task = $_POST['task'];   // Get this from Ext
  }
  switch($task){
    case "LISTING":              // Give the entire list
      getList();
      break;
    default:
      echo "{failure:true}";  // Simple 1-dim JSON array to tell Ext the request failed.
      break;
  }

function getList(){
	global $jsonresult,$cn;
// begin Recordset
	$query_Recordset1 = "SELECT * FROM persona";
	$Recordset1 = $cn->SelectLimit($query_Recordset1) or die($cn->ErrorMsg());
	$totalRows_Recordset1 = $Recordset1->RecordCount();
	// end Recordset
	
	
	
	$arrayVar=array();
	$i=0;
	while (!$Recordset1->EOF){
		$arrayVar[$i]["rut_persona"] = $Recordset1->Fields("rut_persona");
		$arrayVar[$i]["codigo_ciudad"] = $Recordset1->Fields("codigo_ciudad");
		$arrayVar[$i]["nombre_persona"] = $Recordset1->Fields("nombre_persona");
		$arrayVar[$i]["paterno_persona"] = $Recordset1->Fields("paterno_persona");
		$arrayVar[$i]["materno_persona"] = $Recordset1->Fields("materno_persona");
		$arrayVar[$i]["fechanac_persona"] = codeDate($Recordset1->Fields("fechanac_persona"));		
		$arrayVar[$i]["email_persona"] = $Recordset1->Fields("email_persona");
		$arrayVar[$i]["credencial_persona"] = $Recordset1->Fields("credencial_persona");
	
		$i++;
		
		
		
		
	
		$Recordset1->MoveNext(); 
	}
	
	
	
	$jsonresult = json_encode($arrayVar) ;
	$Recordset1->Close();
	
	echo '({"total":"'.$totalRows_Recordset1.'","results":'.$jsonresult.'})';
}

function codeDate ($date) {
	$tab = explode ("-", $date);
	$r = $tab[1]."/".$tab[2]."/".$tab[0];
	return $r;
}



?>
